﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace GtaAPIClient
{
    class Config
    {
        public string serverNmae { get; set; }

        public string[] brokers { get; set; }

        public int timeout { get; set; }

        public int threadNum { get; set;}

        public Config()
        {
            XmlDocument xml = new XmlDocument();
            xml.Load("SystemConfig.xml");
            XmlNode root = xml.SelectSingleNode("zbus");
            if (root != null)
            {
                XmlNodeList nodeList = root.ChildNodes;
                foreach (XmlNode xn in nodeList)
                {
                    XmlElement xe = (XmlElement)xn;

                    if (xe.GetAttribute("name") == "serverName")
                    {
                        this.serverNmae = xe.GetAttribute("value");
                    }
                    if (xe.GetAttribute("name") == "brokers")
                    {
                        if (xe.HasChildNodes)
                        {
                            XmlNodeList brokerList = xe.ChildNodes;
                            if (brokerList != null)
                            {
                                int c = brokerList.Count;
                                brokers = new string[c];
                                int i = 0;
                                foreach (XmlNode xn1 in brokerList)
                                {
                                    XmlElement xe1 = (XmlElement)xn1;
                                    brokers[i++] = xe1.InnerText;
                                }
                            }
                        }
                    }
                    if (xe.GetAttribute("name") == "timeout")
                    {
                        this.timeout = Int32.Parse(xe.GetAttribute("value"));
                    }
                    if (xe.GetAttribute("name") == "threadNum")
                    {
                        this.threadNum = Int32.Parse(xe.GetAttribute("value"));
                    }
                }
            }
        }

    }
}
